(deftemplate persoana
    (slot nationalitate)
    (slot pet)
    (slot tigari)
    (slot casa)
)

(foreach ?n (create$ rus englez spaniol)
    (foreach ?p (create$ cal caine lup)
        (foreach ?t (create$ LM KENT LS)
            (foreach ?c (create$ 1 2 3)
             (assert (persoana (nationalitate ?n) (pet ?p) (tigari ?t) (casa ?c))))
            )
        )
 )

(facts)
(run)

(defrule regula
    (persoana (nationalitate ?n1 & englez) (pet ?p1) (tigari ?t1) (casa ?c1 & 1)) ;;?c1 & 1 == c1=1
    (persoana (nationalitate ?n2 & rus & ~?n1) (pet ?p2 & cal & ~?p1) (tigari ?t2 & ~?t1) (casa ?c2 & ~?c1))
    (persoana (nationalitate ?n3 & spaniol & ~?n1 & ~?n2) (pet ?p3 & ~?p2 & ~?p1) (tigari ?t3 & KENT & ~?t2 & ~?t1) (casa ?c3 & ~?c2 & ~?c1))
   
    =>
    (printout t crlf "****Solutia********" crlf)
    (printout t "Persoana de nationalitate " ?n1 " fumeaza " ?t1 " are " ?p1 " si casa " ?c1 crlf)
    (printout t "Persoana de nationalitate " ?n2 " fumeaza " ?t2 " are " ?p2 " si casa " ?c2 crlf)
    (printout t "Persoana de nationalitate " ?n3 " fumeaza " ?t3 " are " ?p3 " si casa " ?c3 crlf)
 )

(run)

(printout t "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" crlf)

(defrule regula2
    (persoana (nationalitate ?na) (pet ?pa & lup)(tigari ?ta & ~LS) (casa ?ca))
    (persoana (nationalitate ?nb & ~?na) (pet ?pb & ~?pa) (tigari ?tb & LS & ~?ta) (casa ?cb & ~ca))
   ?f1 <- (persoana (nationalitate ?n1 & englez) (pet ?p1) (tigari ?t1) (casa ?c1 &1))
    ?f2 <- (persoana (nationalitate ?n2 & rus & ~?n1 & ~?na) (pet ?p2 & cal & ~?p1 & ~?pa) (tigari ?t2 & ~?t1 & ~?ta) (casa ?c2 & ~?c1 & ~?ca )) 
    ?f3 <-(persoana (nationalitate ?n3 & spaniol & ~?n1 & ~?n2 & ~?nb ) (pet ?p3 & ~?p1 & ~?p2 & ~?pb) (tigari ?t3 & KENT & ~?t1 & ~?t2 & ~?tb) (casa ?c3 &  ~?c1 & ~?c2  & ~?cb))
    
    (test  (or (neq ?p1 lup)(neq ?t1 LS)))
    (test (or (neq ?p3 lup)(neq ?c3 3))) 
    =>
    
    (retract ?f1)
    (retract ?f2)
    (retract ?f3)
    (printout t "Persoana de nationalitate " ?n1 " fumeaza " ?t1 " are " ?p1 " si casa " ?c1 crlf)
    (printout t "Persoana de nationalitate " ?n2 " fumeaza " ?t2 " are " ?p2 " si casa " ?c2 crlf)
    (printout t "Persoana de nationalitate " ?n3 " fumeaza " ?t3 " are " ?p3 " si casa " ?c3 crlf)
    )

(run)